<!-- user表单弹窗 -->
<form id="authoritie-form" lay-filter="authoritie-form" class="layui-form model-form">
    <input name="authorityId" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">权限名称</label>
        <div class="layui-input-block">
            <input name="authorityName" placeholder="请输入权限名称" type="text" class="layui-input" maxlength="50"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限标识</label>
        <div class="layui-input-block">
            <input name="authority" placeholder="请输入权限标识" type="text" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单url</label>
        <div class="layui-input-block">
            <input name="menuUrl" placeholder="请输入菜单url" type="text" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单图标</label>
        <div class="layui-input-block">
            <input name="menuIcon" placeholder="请输入菜单图标" type="text" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否为菜单</label>
        <div class="layui-input-block">
            <input type="radio" name="isMenu" value="0" title="是" checked/>
            <input type="radio" name="isMenu" value="1" title="否"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序号</label>
        <div class="layui-input-block">
            <input name="orderNumber" placeholder="请输入排序号" type="number" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上级菜单</label>
        <div class="layui-input-block">
            <select name="parentId">
                <option value="-1">--请选择--</option>
                <% for(authoritie in authorities) { %>
                <option value="${authoritie.authorityId}">${authoritie.authorityName}</option>
                <% } %>
            </select>
        </div>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="authoritie-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;

        form.render('radio');
        form.render('select');

        var url = 'system/authorities/add';
        // 回显user数据
        var authoritie = admin.getTempData('t_authoritie');
        if (authoritie) {
            url = 'system/authorities/update';
            authoritie.isMenu = authoritie.isMenu.toString();
            form.val('authoritie-form', authoritie);
        }

        // 表单提交事件
        form.on('submit(authoritie-form-submit)', function (data) {
            layer.load(2);
            $.post(url, data.field, function (data) {
                layer.closeAll('loading');
                if (data.code == 200) {
                    layer.msg(data.msg, {icon: 1});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2});
                }
            });
            return false;
        });
    });
</script>